<!DOCTYPE html>
<html lang='en'>

<head>
  <meta charset='UTF-8'>
  <meta http-equiv='X-UA-Compatible' content='IE=edge'>
  <meta name='viewport' content='width=device-width, initial-scale=1.0'>
  <title>Document</title>
  <script src='https://cdn.jsdelivr.net/npm/vue/dist/vue.js'></script>
</head>

<body>
  <template id="faCpn">
    <div>
      <h2>{{faMessage}}</h2>
      <p>app的message:{{appmessage}}</p>
      <p>-----------------------------props验证----------------</p>
      <p>nickname:{{nickname}}</p>
      <p>uname:{{uname}}</p>
      <p>age:{{age}}</p>
      <p>lovemovies:{{lovemovies}}</p>
      <p>book:{{book}}</p>
      <p>-----------------------------props验证----------------</p>
      <ch-cpn :famessage1="faMessage"></ch-cpn>
    </div>
  </template>
  <template id="chCpn">
    <div>
      <h2>{{chMessage}}</h2>
      <p>父组件的信息：{{famessage1}}</p>
    </div>
  </template>
  <div id='app'>
    <h2>{{message}}</h2>
    <fa-cpn :appmessage="message" :uname="uname" :nickname="nickname" :book="book"></fa-cpn>
  </div>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        message: 'hello world',
        nickname: 'cuifan',
        uname: 'simon',
        book: {
          price: 100
        }
      },
      components: {
        faCpn: {
          template: '#faCpn',
          props: {
            appmessage: String,
            nickname: [String, Number],
            uname: {
              type: String,
              required: true
            },
            age: {
              type: Number,
              default: 20
            },
            lovemovies: {
              type: Array,
              default () {
                return [1, 2, 3, 4]
              }
            },
            book: {
              validator(value) {
                return value.price > 20
              }
            }
          },
          data() {
            return {
              faMessage: '我是父亲'
            }
          },
          components: {
            'chCpn': {
              template: '#chCpn',
              props: ['famessage1'],
              data() {
                return {
                  chMessage: '我是孩子'
                }
              }
            }
          }
        }
      }
    })
  </script>
</body>

</html>